cap log close
log using "Z:\Angrist Work\Web Papers\Angrist_1996\Angrist1996_Tabe4.log", replace

*********************************
* PROGRAM: Angrist1996_Table4	 
* PROGRAMMER: Simone Schaner	 
* PURPOSE: Recreates Table 4 of	 
*	Angrist (1996)				 
* DATE CREATED: 11/3/07			 
*********************************

clear
set mem 150m
set more off

cd "Z:\Angrist Work\Web Papers\Angrist_1996"

use index1
	sort date
	save, replace
	
use data8191, clear

* MAKE VARIABLES
g byte count=1
g byte wis= (workloc=="JLEM" | workloc=="ISRAEL") if workloc~=""
g byte gazan= region=="GAZA"
ren v36 weight

g byte y88= year==88
g byte y89= year==89 
g byte y90= year==90
g byte y91= year==91

* DATE RESTRICTION
keep if date>=87

drop daywage lnday lnmnth
g daywage= mnthwage/wrkdays if wrkdays>0
g lnwork=ln(wrkdays) if wrkdays>0
g lnday=ln(daywage)
g lnmnth= ln(mnthwage)

* ROUGH HOURLY WAGE
g hrsday= 4.35*(hourslw/wrkdays) if wrkdays>0
	g hourwage= daywage/hrsday if hrsday>0
	g lnhour= ln(hourwage) if hourwage>0
	
g byte camp= sample==3
g byte city= sample==1

g indgroup= int(ind/10)
	g c_ind="agric" if indgroup==0
		replace c_ind="const" if indgroup==4
		replace c_ind="other" if c_ind==""

sort date workloc c_ind

merge date using index1
	tab _merge
	drop _merge
	
* DEFLATE MICRO DATA
replace lnday= lnday-ln(index)+ln(48179)
replace lnmnth= lnmnth-ln(index)+ln(48179)
replace mnthwage= mnthwage*(48179/index)
replace daywage= daywage*(48179/index)

g specwage= mnthwage
	replace specwage=0 if mnthwage==.

tempfile two twospec
	
	sort date region
	save "`twospec'", replace

keep if workloc=="WBANK" | workloc=="GAZA" | workloc=="JLEM" | workloc=="ISRAEL"

	sort date workloc c_ind
	save "`two'", replace
	
collapse (mean) lnday lnmnth lnwork [w=weight], by(date workloc c_ind)
	ren lnday mlnday
	ren lnmnth mlnmnth
	ren lnwork mlnwork
	
	sort date workloc c_ind

tempfile tomerge regions
		save "`tomerge'", replace

keep if workloc=="GAZA" | workloc=="WBANK"
reshape wide mlnday mlnmnth mlnwork, i(date c_ind) j(workloc) string
	ren mlnworkWBANK wlnwork
	ren mlndayWBANK wlnwage
	ren mlnworkGAZA glnwork
	ren mlndayGAZA glnwage
keep date c_ind glnwork glnwage wlnwork wlnwage
	sort date c_ind
	save "`regions'"

* MERGE BACK ONTO CORE DATASET	
use "`tomerge'", clear

merge date workloc c_ind using "`two'"
	tab _merge
	drop _merge
	save "`two'", replace
	
use "`twospec'", clear
	g wrlnwork= lnwork if region=="WBANK"
	g wrmnth= specwage if region=="WBANK"
	g wrdays= wrkdays if region=="WBANK"

	g grlnwork= lnwork if region=="GAZA"
	g grmnth= specwage if region=="GAZA"
	g grdays= wrkdays if region=="GAZA"
	
collapse (mean) wrlnwork wrmnth wrdays grlnwork grmnth grdays [w=weight], by(date)
	g wrlnmnth=ln(wrmnth)
	g grlnmnth= ln(grmnth)
		
tempfile region2
	sort date
	save "`region2'", replace
	
use "`two'"
	sort date c_ind
	merge date c_ind using "`regions'"
		tab _merge
		drop _merge

sort date
merge date using "`region2'"
tab _merge 
drop _merge

g byte q2= qtr==2
g byte q3= qtr==3
g byte q4= qtr==4

* FOR RESTRICTED REGS COMPUTE DIF BY LOC W/ MICRO DATA ON LHS WAGE EQNS
g byte gulfwar= date>=91 & date<=91.25
g byte gulf1= date==91
g byte gulf2= date==91.25

*  GENERATE MORE VARS FOR REGS
g byte yr88= year==88
	g byte yr89= year==89
	g byte yr90= year==90
	g byte yr91= year==91
	
g diswb2= diswb^2
g disgs2= disgs^2
g curwb2= curwb^2
g curgs2= curgs^2

g trend= (date-87)*4
g trend2= trend^2

* MICRO DATA CONTROLS
g byte ed13_15= educ>=13 & educ<=15
g byte ed16plus= educ>=16
g byte age2= age>=25 & age<=34
g byte age3= age>=35 & age<=44
g byte age4= age>=45 & age<=54
g byte age5= age>=55 & age<=64

g byte dagric= c_ind=="agric"
g byte dconst= c_ind=="const"

* ONLY THOSE WORKING IN ISRAEL
keep if workloc=="ISRAEL"

g gdifwage= lnday-glnwage 
g gdifwork= mlnwork-glnwork 

g wdifwage= lnday-wlnwage 
g wdifwork= mlnwork-wlnwork


* REGRESSIONS - YOU MUST HAVE IVREG2 INSTALLED - TYPE "findit ivreg2 in STATA to download"

* COLUMN 1
reg lnday glnwage mlnwork glnwork dagric dconst q2-q4 yr88-yr91 age2-age5 ed13_15 ///
	ed16plus married disgs disgs2 gulf1 gulf2
	
* COLUMN 2
ivreg2 lnday (glnwage mlnwork glnwork= curwb curwb2 curgs curgs2) dagric dconst q2-q4 yr88-yr91 age2-age5 ed13_15 ///
	ed16plus married disgs disgs2 gulf1 gulf2
* IMPLIED ELASTICITY ESTIMATES
di 1/_b[mlnwork]
di -1*(1/_b[glnwork])*_b[glnwage]

* COLUMN 3
ivreg2 lnday (glnwage gdifwork grlnmnth= curwb curwb2 curgs curgs2) dagric dconst q2-q4 yr88-yr91 age2-age5 ed13_15 ///
	ed16plus married disgs disgs2 gulf1 gulf2
di 1/_b[gdifwork]
di -1*(1/_b[gdifwork])*_b[glnwage]
di _b[grlnmnth]*(1/_b[gdifwork])

* COLUMN 4
ivreg2 gdifwage (mlnwork glnwork grlnmnth= curwb curwb2 curgs curgs2) dagric dconst q2-q4 yr88-yr91 age2-age5 ed13_15 ///
	ed16plus married disgs disgs2 gulf1 gulf2
di 1/_b[mlnwork]
di (1/_b[glnwork])*-1
di _b[grlnmnth]*-1*(1/_b[glnwork])

* COLUMN 5
ivreg2 lnday (glnwage mlnwork glnwork grlnmnth= curwb curwb2 curgs curgs2) dagric dconst q2-q4 yr88-yr91 age2-age5 ed13_15 ///
	ed16plus married disgs disgs2 gulf1 gulf2
di 1/_b[mlnwork]
di (1/_b[glnwork])*_b[glnwage]*-1
di _b[grlnmnth]*(1/_b[glnwork])*-1

* COLUMN 6
reg lnday wlnwage mlnwork wlnwork dagric dconst q2-q4 yr88-yr91 age2-age5 ed13_15 ///
	ed16plus married diswb diswb2 gulf1 gulf2

* COLUMN 7
ivreg2 lnday (wlnwage mlnwork wlnwork= curwb curwb2 curgs curgs2) dagric dconst q2-q4 yr88-yr91 age2-age5 ed13_15 ///
	ed16plus married diswb diswb2 gulf1 gulf2
* IMPLIED ELASTICITY ESTIMATES
di 1/_b[mlnwork]
di -1*(1/_b[wlnwork])*_b[wlnwage]

* COLUMN 8
ivreg2 lnday (wlnwage wdifwork wrlnmnth= curwb curwb2 curgs curgs2) dagric dconst q2-q4 yr88-yr91 age2-age5 ed13_15 ///
	ed16plus married diswb diswb2 gulf1 gulf2
di 1/_b[wdifwork]
di -1*(1/_b[wdifwork])*_b[wlnwage]
di _b[wrlnmnth]*(1/_b[wdifwork])

* COLUMN 9
ivreg2 wdifwage (mlnwork wlnwork wrlnmnth= curwb curwb2 curgs curgs2) dagric dconst q2-q4 yr88-yr91 age2-age5 ed13_15 ///
	ed16plus married diswb diswb2 gulf1 gulf2
di 1/_b[mlnwork]
di (1/_b[wlnwork])*-1
di _b[wrlnmnth]*-1*(1/_b[wlnwork])

* COLUMN 10
ivreg2 lnday (wlnwage mlnwork wlnwork wrlnmnth= curwb curwb2 curgs curgs2) dagric dconst q2-q4 yr88-yr91 age2-age5 ed13_15 ///
	ed16plus married diswb diswb2 gulf1 gulf2
di 1/_b[mlnwork]
di (1/_b[wlnwork])*_b[wlnwage]
di _b[wrlnmnth]*(1/_b[wlnwork])*-1
	
log close
